package cn.bellychang.ood.atmsimulator;

import org.joda.money.CurrencyUnit;
import org.joda.money.Money;

/**
 * @author ChangLiang
 * @date 2020/5/21
 */
public class AtmSimulator {

    public static final char DEFAULT_INPUT = '\u0000';



    public static void main(String[] args) {
        Atm atm = new Atm();
        atm.setHoldMoney(Money.of(CurrencyUnit.of("CNY"),50000));
        char command = DEFAULT_INPUT;

        while (CommandLineInput.EXIT.getShortCmd() != command) {
            atm.printOptions();
            String input = atm.readInput();
            char[] inputChars = input.length() == 1 ? input.toCharArray() : new char[]{DEFAULT_INPUT};
            command = inputChars[0];
            CommandLineInput commandLineInput = CommandLineInput.getCommandLintInputForInput(command);
            atm.processInput(commandLineInput);
            try {
                if (commandLineInput.getShortCmd() == CommandLineInput.EJECT_CARD.getShortCmd()) {
                    atm.print();
                    atm = new Atm();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
